package com.study.usercenter.library;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext;
import org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient;
import org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonRequest;
import org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.xml.transform.Result;

@Component
public class OrderLibrary {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private OkHttpClient okHttpClient;

    @HystrixCommand(fallbackMethod = "getOrderInfoFail")
    public String getOrderInfo(Integer id) {
        String url = "http://order-center/order/info/" + id.toString();
        String orderInfo = restTemplate.getForObject(url,String.class);
        System.out.println("当前线程为：" + Thread.currentThread().getName());
        return orderInfo;
    }

    public String getOrderInfoFail(Integer id) {
        return "我是快速失败页面";
    }

}
